//
//  CaoZuoDanQueryNavBar.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/9/25.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "CaoZuoDanQueryNavBar.h"

@interface CaoZuoDanQueryNavBar ()

@property (nonatomic, strong) UIButton *backBtn;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIButton *btn1;
@property (nonatomic, strong) UIButton *btn2;

@end

@implementation CaoZuoDanQueryNavBar

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = HexColor(0xffffff);
        
//        self.backBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, StatusBarHeight+(NaviHeight - StatusBarHeight - 24) * 0.5, 24, 24)];
//        [self.backBtn setImage:[UIImage imageNamed:@"nav_back"] forState:0];
//        [self.backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:self.backBtn];
        
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(15, StatusBarHeight+(NaviHeight - StatusBarHeight - 25) * 0.5, 120, 25)];
        self.titleLab.textColor = HexColor(0x000000);
        self.titleLab.font = BoldFontOfSize(24);
        [self addSubview:self.titleLab];
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(ScreenW - 15 - 133, StatusBarHeight+(NaviHeight - StatusBarHeight - 40) * 0.5, 133, 40)];
        self.bgView.backgroundColor = HexColor(0xF2F2F5);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 8;
        [self addSubview:self.bgView];
        
        self.btn1 = [[UIButton alloc] initWithFrame:CGRectMake(4, 4, 62, 32)];
        [self.btn1 setTitle:@"未完成" forState:0];
        self.btn1.titleLabel.font = BoldFontOfSize(14);
        [self.btn1 setTitleColor:HexColor(0xffffff) forState:0];
        self.btn1.layer.masksToBounds = YES;
        self.btn1.layer.cornerRadius = 6;
        [self.btn1 setBackgroundColor:Color_ThemeColor];
        [self.btn1 addTarget:self action:@selector(btn1Click) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.btn1];
        
        self.btn2 = [[UIButton alloc] initWithFrame:CGRectMake(self.btn1.nim_right + 4, 4, self.bgView.nim_width - 4 - (self.btn1.nim_right + 4), 32)];
        [self.btn2 setTitle:@"已完成" forState:0];
        self.btn2.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn2 setTitleColor:HexColor(0x9C9DB3) forState:0];
        self.btn2.layer.masksToBounds = YES;
        self.btn2.layer.cornerRadius = 6;
        [self.btn2 setBackgroundColor:HexColor(0xF2F2F5)];
        [self.btn2 addTarget:self action:@selector(btn2Click) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.btn2];
    }
    return self;
}

-(void)setTitleStr:(NSString *)titleStr {
    _titleStr = titleStr;
    self.titleLab.text = titleStr;
}

- (void)btn1Click {
    self.btn1.titleLabel.font = BoldFontOfSize(14);
    [self.btn1 setTitleColor:HexColor(0xffffff) forState:0];
    [self.btn1 setBackgroundColor:Color_ThemeColor];
    
    self.btn2.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.btn2 setTitleColor:HexColor(0x9C9DB3) forState:0];
    [self.btn2 setBackgroundColor:HexColor(0xF2F2F5)];
    if (self.changeBlock) {
        self.changeBlock(1);
    }
}

- (void)btn2Click {
    self.btn2.titleLabel.font = BoldFontOfSize(14);
    [self.btn2 setTitleColor:HexColor(0xffffff) forState:0];
    [self.btn2 setBackgroundColor:Color_ThemeColor];
    
    self.btn1.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.btn1 setTitleColor:HexColor(0x9C9DB3) forState:0];
    [self.btn1 setBackgroundColor:HexColor(0xF2F2F5)];
    if (self.changeBlock) {
        self.changeBlock(2);
    }
}

- (void)backClick {
    if (self.backBlock) {
        self.backBlock();
    }
}

@end
